package com.jordi.tetris.model;

import java.util.Random;

import com.jordi.tetris.model.pieces.IPiece;
import com.jordi.tetris.model.pieces.JPiece;
import com.jordi.tetris.model.pieces.LPiece;
import com.jordi.tetris.model.pieces.QPiece;
import com.jordi.tetris.model.pieces.SPiece;
import com.jordi.tetris.model.pieces.TPiece;
import com.jordi.tetris.model.pieces.ZPiece;

public class PieceFactory {

	@SuppressWarnings("rawtypes")
	private static final Class[] pieceTypes = { LPiece.class, ZPiece.class,
			TPiece.class, QPiece.class, IPiece.class, JPiece.class,
			SPiece.class };

	private static final int numPieces = pieceTypes.length;

	private static final Random random = new Random();

	public static Piece createPiece() {

		Piece piece = null;

		try {
			piece = (Piece) pieceTypes[random.nextInt(numPieces)].newInstance();
		} catch (InstantiationException e) {
		} catch (IllegalAccessException e) {
		}

		return piece;
	}
}
